/*
 * @description: 启动文件
 * @Date: 2023-03-21 14:46:31
 * @example: 
 * @params: 
 */
const express = require('express');
const cors = require('cors')
const options = require("./utils/swagger/index")
const app = express();
const expressSwagger = require('express-swagger-generator')(app);
expressSwagger(options)
const server = require('http').createServer(app);
const port = process.env.PORT || 3000;

app.use('/public/', express.static('./public/'))

/** 引入路由模块 */
app.use(require("./router/dataPush"))   //数据源
app.use(require("./router/sensor")) // 传感器数据
app.use(require("./router/layout")) // DIY DASHBORD
app.use(cors())
app.all("*", function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Headers", "Content-Type");
    res.header("Access-Control-Allow-Headers", "Authorization");
    next();
  });

server.listen(port,()=>{
    console.log('Server listening 127.0.0.1:3000', port);
    console.log('Swagger doc is listening 127.0.0.1:3000/swagger ')
})